import { createStore } from 'vuex'

export default createStore({
  state: {
    user: null,
    modUser: null,
    article: null
  },
  mutations: {
    LOGIN(state, user) {
      state.user = user
      window.localStorage.setItem("user", JSON.stringify(user))
    },

    LOGOUT(state) {
      window.localStorage.removeItem("user")
      state.user = null
    },

    ADD_ARTICLE(state, article) {
      state.article = article
      window.localStorage.setItem("article", JSON.stringify(article))
    },

    DELETE_ARTICLE() {
      window.localStorage.removeItem("article")
    },

      ADD_MOD_USER(state, modUser) {
          state.modUser = modUser
          window.localStorage.setItem("modUser", JSON.stringify(modUser))
      },

      DELETE_MOD_USER() {
          window.localStorage.removeItem("modUser")
      },
  },
  actions: {
      // 存储用户信息
      storeInfo(context, payload) {
        context.commit("LOGIN", payload)
      },

      // 移除用户信息
      removeInfo(context) {
        context.commit("LOGOUT")
      },

      // 添加文章信息
      addModUser(context, modUser) {
        context.commit("ADD_MOD_USER", modUser)
      },

      // 添加文章信息
      removeModUser(context) {
        context.commit("DELETE_MOD_USER")
      },

      // 添加文章信息
      addArticle(context, article) {
        context.commit("ADD_ARTICLE", article)
      },

      // 添加文章信息
      removeArticle(context) {
        context.commit("DELETE_ARTICLE")
      },
  },
  modules: {
  }
})
